<?php echo $this->Html->script('tinymce/tinymce.min');?>

<div class="col-lg-12">

	<div class="portlet">
    <div class="portlet-title">
        <div class="caption">
            <i class="fa fa-plus"></i><?= isset($this->data[$als]['id']) ? 'Sửa' : 'Thêm mới'; ?>
        </div>
    </div>


	<div class="portlet-body form">
		<?php echo $this->Form->create($als, array('class' => 'form-horizontal form-bordered', 'type' => 'file'));?>
		<?php echo $this->Form->hidden($als.'.id' )?>
		<div class="portlet-body">
			<div class="form-body">
				<div class="form-group">
					<label class="col-sm-3 control-label"><?= __('Danh mục');?></label>
					<div class="col-sm-5">
						<?php echo $this->Form->input($als.'.category_id', array( 'label' => false, 'div' => false, 'class' => 'form-control', 'options' => $categories, 'default' => $category_id ) )?>
					</div>
				</div>
				<div class="form-group">
					<label class="col-sm-3 control-label"><?= __('Tên'); ?></label>
					<div class="col-sm-5">
						<?php echo $this->Form->input($als.'.name', array( 'label' => false, 'div' => false, 'class' => 'form-control', 'placeholder' => 'Nhập tên' ) )?>
					</div>
				</div>

				<div class="form-group">
					<label class="col-sm-3 control-label"><?= __('Tên gọi khác'); ?></label>
					<div class="col-sm-5">
						<?php echo $this->Form->input($als.'.als', array( 'label' => false, 'div' => false, 'class' => 'form-control alias', 'placeholder' => 'ten-goi-khac' ) )?>
					</div>
				</div>

				<div class="form-group">
					<label class="col-sm-3 control-label"><?= __('Giá'); ?></label>
					<div class="col-sm-5">
						<?php echo $this->Form->input($als.'.price', array( 'label' => false, 'div' => false, 'class' => 'form-control', 'placeholder' => 'Nhập giá' ) )?>
					</div>
				</div>

				<div class="form-group">
					<label class="col-sm-3 control-label"><?= __('Bảo hành'); ?></label>
					<div class="col-sm-5">
						<?php echo $this->Form->input($als.'.warranty', array( 'label' => false, 'div' => false, 'class' => 'form-control', 'placeholder' => 'Nhập nội dung bảo hành' ) )?>
					</div>
				</div>

				<div class="form-group">
					<label class="col-sm-3 control-label">Miêu tả</label>
					<div class="col-sm-9">
						<?php echo $this->Form->textarea($als.'.desc', array( 'label' => false, 'div' => false, 'class' => 'form-control tnmc', 'placeholder' => 'Nhập nội dung miêu tả' ) )?>
					</div>
				</div>

				<div class="form-group">
					<label class="col-sm-3 control-label">Mới</label>
					<div class="col-sm-5">
						<div class="radio-list">
							<label class="radio-inline">
								<input type="radio" name="data[<?= $als ?>][new]" value="1" <?php echo !isset($this->data[$als]['new']) || $this->data[$als]['new'] == 1 ? 'checked="checked"' : '' ?> />
								<?= __('Có')?>
							</label>
							<label class="radio-inline">
								<input type="radio" name="data[<?= $als ?>][new]" value="0" <?php echo isset($this->data[$als]['new']) && $this->data[$als]['new'] == 0 ? 'checked="checked"' : '' ?>/>
								<?= __('Không')?>
							</label>
						</div>
					</div>
				</div>

				<div class="form-group">
					<label class="col-sm-3 control-label">Nỗi bật</label>
					<div class="col-sm-5">
						<div class="radio-list">
							<label class="radio-inline">
								<input type="radio" name="data[<?= $als ?>][prominent]" value="1" <?php echo isset($this->data[$als]['prominent']) && $this->data[$als]['prominent'] == 1 ? 'checked="checked"' : '' ?> />
								<?= __('Có')?>
							</label>
							<label class="radio-inline">
								<input type="radio" name="data[<?= $als ?>][prominent]" value="0" <?php echo !isset($this->data[$als]['prominent']) || $this->data[$als]['prominent'] == 0 ? 'checked="checked"' : '' ?>/>
								<?= __('Không')?>
							</label>
						</div>
					</div>
				</div>

				<div class="form-group">
					<label class="col-sm-3 control-label">Bán chạy</label>
					<div class="col-sm-5">
						<div class="radio-list">
							<label class="radio-inline">
								<input type="radio" name="data[<?= $als ?>][run]" value="1" <?php echo isset($this->data[$als]['run']) && $this->data[$als]['run'] == 1 ? 'checked="checked"' : '' ?> />
								<?= __('Có')?>
							</label>
							<label class="radio-inline">
								<input type="radio" name="data[<?= $als ?>][run]" value="0" <?php echo !isset($this->data[$als]['run']) || $this->data[$als]['run'] == 0 ? 'checked="checked"' : '' ?>/>
								<?= __('Không')?>
							</label>
						</div>
					</div>
				</div>

				<div class="form-group">
					<label class="col-sm-3 control-label">Hình ảnh đại diện</label>
					<div class="col-sm-9">
						<?php if(!empty($this->data[$als]['thumb']) && is_string($this->data[$als]['thumb'])):?>
						<div class="row">
							<div class="col-sm-7 col-md-3">
								<div class="thumbnail">
									<?php echo $this->Form->hidden($als.'.thumb_old', array('value' => $this->data[$als]['thumb']) )?>
									<img src="<?= PUBLIC_THUMB_SHOW. $this->data[$als]['thumb'] ?>" alt="...">
								</div>
							</div>
						</div>
						<?php endif;?>

						<div class="row">
							<div class="col-sm-5"><input type="file" class="form-control" name="data[<?= $als ?>][thumb]"/></div>
						</div>
					</div>
				</div>

				<div class="form-group">
					<label class="col-sm-3 control-label">Hình ảnh</label>
					<div class="col-sm-9">
						<?php if(isset($images)):?>
						<div class="row">
							<?php $i = 0; foreach($images as $img): $i++?>
							<div class="col-sm-7 col-md-3 item" id="<?php echo $img['Image']['id']; ?>" data-als="<?= $als ?>">
								<div class="thumbnail">
									<img src="<?php echo PUBLIC_THUMB_SHOW. $img['Image']['image'] ?>" alt="...">

									<div class="tools tools-bottom">
										<a href="#">
											<i class="fa fa-times text-white"></i>
										</a>
									</div>
								</div>
							</div>
							<?php if($i == 4) : $i = 0;?>
							<div class="clearfix"></div>
							<?php endif; ?>
							<?php endforeach;?>
						</div>
						<?php endif;?>

						<div class="clearfix mb20 line"></div>
						<div class="item row mb10 clearfix">
							<div class="col-sm-5"><input type="file" class="form-control" name="data[<?= $als ?>][images][]"/></div>
							<div class="col-sm-7">
								<a href="#" class="btn btn-sm btn-primary add"><i class="fa fa-plus icon-only"></i></a>
								<a href="#" class="btn btn-sm btn-danger del hide"><i class="fa fa-trash-o icon-only"></i></a>
							</div>
						</div>
					</div>
				</div>

				<div class="form-group">
					<label class="col-sm-3 control-label">Chi tiết</label>
					<div class="col-sm-9">
						<?php if(empty($this->data['ProductAtribute'])): ?>
						<div class="row item" data-sort="0">
							<label class="col-sm-1 control-label pt7">Tên</label>
							<div class="col-sm-3">
								<input type="text" class="form-control" name="data[ProductAtribute][0][name]" placeholder="Nhập tên" />
							</div>
							<label class="col-sm-2 control-label pt7">Giá trị</label>
							<div class="col-sm-4">
								<input type="text" class="form-control" name="data[ProductAtribute][0][value]" placeholder="Nhập giá trị" />
							</div>
							<div class="col-sm-2">
								<a href="#" class="btn btn-sm btn-primary add"><i class="fa fa-plus icon-only"></i></a>
								<a href="#" class="btn btn-sm btn-danger del "><i class="fa fa-trash-o icon-only"></i></a>
							</div>
						</div>
						<?php else: ?>
						<?php $count = count($this->data['ProductAtribute']);  foreach($this->data['ProductAtribute'] as $k => $v): ?>
						<div class="row item" data-sort="<?= $k ?>">
							<label class="col-sm-1 control-label pt7">Tên</label>
							<div class="col-sm-3">
								<input type="text" class="form-control <?= !empty($v['errors']['name'][0]) ? ' form-error' : '' ?>" name="data[ProductAtribute][<?= $k ?>][name]" placeholder="Nhập tên" value="<?= $v['name'] ?>" />
								<?php if(!empty($v['errors']['name'][0])):?>
								<div class="error-message"><?= $v['errors']['name'][0] ?></div>
								<?php endif; ?>
							</div>
							<label class="col-sm-2 control-label pt7">Giá trị</label>
							<div class="col-sm-4">
								<input type="text" class="form-control <?= !empty($v['errors']['value'][0]) ? ' form-error' : '' ?>" name="data[ProductAtribute][<?= $k ?>][value]" placeholder="Nhập giá trị" value="<?= $v['value'] ?>" />
								<?php if(!empty($v['errors']['value'][0])): ?>
								<div class="error-message"><?= $v['errors']['value'][0] ?></div>
								<?php endif; ?>
							</div>
							<div class="col-sm-2">
								<a href="#" class="btn btn-sm btn-primary add <?= $k == ($count - 1) ? '' : 'hide' ?>"><i class="fa fa-plus icon-only"></i></a>
								<a href="#" class="btn btn-sm btn-danger del <?= $count == 1 ? 'hide' : '' ?>"><i class="fa fa-trash-o icon-only"></i></a>
							</div>
						</div>
						<?php endforeach; ?>
						<?php endif; ?>
					</div>
				</div>
			</div>
			<div class="form-actions fluid">
				<div class="col-md-offset-3 col-md-9">
					<button type="submit" class="btn btn-success"><?= __('Lưu') ?></button>
					<a href="<?= $this->webroot.'admin/products' ?>" class="btn btn-default">Hủy bỏ</a>
				</div>
			</div>
		</div>
		<?php echo $this->Form->end( ); ?>
	</div><!-- End protet -->

</div>
